{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 没有私钥就别看这个了\n",
    "# 必要的包\n",
    "import base64\n",
    "import gzip\n",
    "from main import decrypt_sm4, PUBLIC_KEY, PRIVATE_KEY\n",
    "# from main import decrypt_sm2 # 代码提供的decrypt_sm2过不了验签，先不用，网上随便搜一个sm在线加密解密，选c1c3c2模式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "公钥：BL7JvEAV7Wci0h5YAysN0BPNVdcUhuyJszJLRwnurav0CGftcrVcvrWeCPBIjIIBF371teRbrCS9V1Wyq7i3Arc=\n",
      "私钥：P3s0+rMuY4Nt5cUWuOCjMhDzVNdom+W0RvdV6ngM+/E=\n"
     ]
    }
   ],
   "source": [
    "# 你可以运行这里copy公钥和私钥(统一的)\n",
    "print(\"公钥：\" + base64.b64encode(PUBLIC_KEY).decode(\"utf-8\"))\n",
    "print(\"私钥：\" + base64.b64encode(PRIVATE_KEY).decode(\"utf-8\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "cipherkey_plaintext = base64.b64decode(\"exS8v5L5FVMBGQo0Yf8RZg==\") # 你的解密后的密钥"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 运行这个，查看解密后的内容\n",
    "text = gzip.decompress(decrypt_sm4(\"(your string)asdf==\", cipherkey_plaintext)).decode()\n",
    "print(text)\n",
    "# 注意gzip，还有python3是严格区分bytes和string类型的，不能混用，记得decode和encode"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "write to ./tasks\\tasklist_8.json\n"
     ]
    }
   ],
   "source": [
    "# 保存到tasklist_{last+1}.json\n",
    "import os\n",
    "path = \"./tasks\"\n",
    "files = os.listdir(path)\n",
    "last = 0\n",
    "target = None\n",
    "if len(files) == 0:\n",
    "    target = os.path.join(path, \"tasklist_0.json\")\n",
    "else:\n",
    "    for file in files:\n",
    "        if f'tasklist_{last}.json' in file:\n",
    "            last += 1\n",
    "        else:\n",
    "            target = os.path.join(path, f\"tasklist_{last}.json\")\n",
    "            break\n",
    "    if target == None:\n",
    "        target = os.path.join(path, f\"tasklist_{last}.json\")\n",
    "with open(file=target,mode='w+', encoding=\"utf-8\") as f:\n",
    "    print(f\"write to {target}\")\n",
    "    f.write(text)\n",
    "    f.flush()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
